<!DOCTYPE html>
<html xmlns:shiro="http://www.w3.org/1999/xhtml">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>付款申请</title>
    <link th:replace="comm/header :: header">
    <style>

    </style>
    <script type="text/javascript">

        function formatEdit(val, row, index) {
            var str = '';
            if(row.cstatus==0&&$("#reapply").length>0){
                str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-1  l-btn l-btn-small l-btn-plain" onclick="searchPayerFun(\'{0}\');" >申请付款</a>', index);
            }
            //如果付款申请提交了
           else if (row.cstatus == 1&&$("#che").length>0&&$("#info").length>0) {
                str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-del1  l-btn l-btn-small l-btn-plain" onclick="cheFun(\'{0}\');" >撤销申请</a>', index);
                str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-2 info  l-btn l-btn-small l-btn-plain" onclick="showDetail(\'{0}\');" >趟数明细</a>', index);
            } else if (row.cstatus == 2 || row.cstatus==4&&$("#info").length>0) {
                if(row.creason!=null&&row.creason!=""&&row.cstatus!=4&&$("#view").length>0){
                    str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit error  l-btn l-btn-small l-btn-plain" onclick="openRemark(\'{0}\');" >查看理由</a>', index);
                }
                str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-2 info  l-btn l-btn-small l-btn-plain" onclick="showDetail(\'{0}\');" >趟数明细</a>', index);
                // str += $.formatString('<a href="javascript:void(0)" class="applypayment-easyui-linkbutton-del primary  l-btn l-btn-small l-btn-plain"  onclick="searchPayerFun(\'{0}\');" >重新申请</a>', index);
            } else if($("#info").length>0){
                str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-2 info  l-btn l-btn-small l-btn-plain" onclick="showDetail(\'{0}\');" >趟数明细</a>', index);
            }
            return str;

        }

        function searchPayerFun(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            $.messager.confirm("系统提示", "申请这笔付款吗?", function (r) {
                if (r) {
                    $.post("/fin/qing/save",
                        {id:row.id},
                        function (result) {
                            if (result.flag) {
                                message("提交成功");
                                $("#dg").datagrid("reload");
                            } else {
                                message(result.info);
                            }
                        })
                }
            })
        }
        function cheFun(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            $.messager.confirm("系统提示", "撤销这笔付款吗?", function (r) {
                if (r) {
                    $.post("/fin/qing/exit",
                        {id:row.id},
                        function (result) {
                            if (result.flag) {
                                message("提交成功");
                                $("#dg").datagrid("reload");
                            } else {
                                message(result.info);
                            }
                        })
                }
            })
        }

        //传项目id
        function rePayAppFun(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            var apaid = row.apaId;
            $.messager.confirm("系统提示", "您确定重新提交这条数据吗?", function (r) {
                if (r) {
                    $.post("/payment/payrequest/reapp", {apaId: apaid}, function (result) {
                        if (result.success) {
                            message("提交成功！")
                            $("#dg").datagrid("reload");
                        } else {
                            message(result.info)
                        }
                    }, "json");
                }
            });
        }

        function searchApplypayment() {
            $("#dg").datagrid('load', {
                "name": $("#s_CaptainName").val()
            });
        }
        function formatterName(value,row) {
            return row.captain.cname;
        }
        function formatterPhone(value,row) {
            return row.captain.phone;
        }
        function formatterBank(value,row) {
            return row.captain.cdepositBank;
        }
        function formatterAccount(value,row) {
            return row.captain.account;
        }

        function formatter3(value, row, index) {
            if (row.cstatus == 2) {
                return '已驳回'
            } else if (row.cstatus == 1) {
                return '申请中';
            } else if(row.cstatus==3){
                return '申请成功';
            }else if(row.cstatus==4){
                return "撤销";
            }else{
                return '未申请';
            }
        }
        function formatter(value, row, index) {
            if (row.paystatus == 0) {
                return '未支付';
            } else {
                return '已支付';
            }
        }

        function formatter1(value, row, index) {
            if (row.piaostatus == 0) {
                return '未开票';
            } else {
                return '已开票';
            }
        }

        function openRemark(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            var reason = row.creason
            $("#reason").val(reason)
            $("#dlgreject").dialog("open").dialog("setTitle", "驳回原因");
        }

        //查询趟数明细
        function showDetail(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            var caphonenum = row.capTelephone;
            var id = row.id;
            console.log(caphonenum)
            $('#dgdetail').datagrid('load', {
                id:id
            });
            $("#showdetail").dialog("open").dialog("setTitle", "趟数明细");
        }
    </script>
</head>
<shiro:hasPermission name="payapp:rejectreason">
    <input type="hidden" id="payapprejectreason"/>
</shiro:hasPermission>
<shiro:hasPermission name="apply:payment:view">
    <input type="hidden" id="view"/>
</shiro:hasPermission>
<shiro:hasPermission name="apply:payment:info">
    <input type="hidden" id="info"/>
</shiro:hasPermission>
<shiro:hasPermission name="apply:payment:reapply">
    <input type="hidden" id="reapply"/>
</shiro:hasPermission>
<shiro:hasPermission name="apply:payment:che">
    <input type="hidden" id="che"/>
</shiro:hasPermission>
<body style="margin: 1px">
<!--明细申请页面展示-->
<div id="showdetail" class="easyui-dialog" style="width: 750px;height: 550px;padding: 10px 20px"
     closed="true" buttons="#showdetail-buttons">
    <table id="dgdetail" class="easyui-datagrid"
           fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
           url="/fin/qing/list" fit="true" toolbar="#tb" method="get">
        <thead>
        <th field="id" width="20" align="center" hidden>编号</th>
        <th field="idcard" width="20" align="center">车牌号</th>
        <th field="ctotal" width="20" align="center">趟数</th>
        <th field="price" width="20" align="center">单价</th>
        <th field="phone" width="20" align="center" formatter="formatterPhone">队长手机</th>
        <th field="payment" width="20" align="center">总价</th>
        </thead>
    </table>


</div>


<input type="hidden" id="applypaymentupdate"/>
<table id="dg" title="付款申请" class="easyui-datagrid"
       fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
       url="/fin/qing/listAll" fit="true" toolbar="#tb" method="get">
    <thead>
    <th field="id" width="20" align="center" hidden>编号</th>
    <th field="cname" width="25" align="center" formatter="formatterName">队长姓名</th>
    <th field="eid" width="15" align="center">企业id</th>
    <th field="payment" width="30" align="center">应付款</th>
    <th field="ctotal" width="15" align="center">趟数</th>
    <th field="cdepositBank" width="30" align="center" formatter="formatterBank">队长开户行</th>
    <th field="phone" width="30" align="center" formatter="formatterPhone" hidden>队长手机</th>
    <th field="account" width="35" align="center" formatter="formatterAccount">队长账户</th>
    <th field="cstatus" width="35" align="center" formatter="formatter3">申请状态</th>
    <th field="paystatus" width="20" align="center" formatter="formatter">支付状态</th>
    <th field="piaostatus" width="20" align="center" formatter="formatter1">开票状态</th>
    <th field="piaonum" width="40" align="center">票据单号</th>
    <th field="shentime" width="65" align="center">审批时间</th>
    <th field="creason" width="50" align="center" hidden>驳回理由</th>
    <th field="proid" width="50" align="center" hidden>项目id</th>
    <th field="op" width="90" align="center" formatter="formatEdit">操作</th>
    </thead>
</table>

<div id="tb">
    &nbsp;队长姓名：&nbsp;<input class="easyui-textbox" id="s_CaptainName" data-options="iconCls:'fa fa-file',iconAlign:'left'" prompt="请输入队长名称" size="20"/>
    <a href="javascript:searchApplypayment()" class="easyui-linkbutton primary" iconCls="icon-search" plain="true">搜索</a>
</div>
<div id="dlgreject" class="easyui-dialog" style="width: 450px;height: 350px;padding: 10px 20px"
     closed="true" buttons="#dlgreject-buttons">
    <table>
        <tr>
            <td>驳回原因：</td>
            <td>
                <textarea rows="5" cols="35" id="reason" name="reason"></textarea>
            </td>
        </tr>
    </table>

</div>


<div id="uploadonlineinfo" class="easyui-dialog" style="width:380px;padding:10px 40px" closed="true">
    <form id="fam" method="post" enctype="multipart/form-data">
        <input type="hidden" id="flag" name="flag">
        <input type="hidden" id="id" name="id">
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $("#dg").datagrid({
            onLoadSuccess: function (data) {
                $('.applypayment-easyui-linkbutton-edit-1').linkbutton({
                    text: '申请付款',
                    plain: true,
                    iconCls: 'icon-edit'
                });
                $('.applypayment-easyui-linkbutton-edit').linkbutton({text: '查看理由', plain: true, iconCls: 'icon-edit'});
                $('.applypayment-easyui-linkbutton-edit-2').linkbutton({
                    text: '趟数明细',
                    plain: true,
                    iconCls: 'icon-edit'
                });
                $('.applypayment-easyui-linkbutton-del').linkbutton({
                    text: '重新申请',
                    plain: true,
                    iconCls: 'icon-remove'
                });
                $('.applypayment-easyui-linkbutton-del1').linkbutton({
                    text: '撤销申请',
                    plain: true,
                    iconCls: 'icon-remove'
                });
                $('#dg').datagrid('fixRowHeight');
            }
        });

    })
</script>
</body>
</html>